package hotel.service.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import hotel.service.ISalesLineItemService;

@Component
public class SalesLineItemServiceImpl<T> extends ServiceImpl<T> implements ISalesLineItemService<T> {

	@Override
	public int getCheckinCount() {
		return dao.getTotalCount("SalesLineItem");
	}

	@Override
	public List<T> paging(int firstResult, int maxResult) {
		return dao.paging("SalesLineItem", firstResult, maxResult);
	}

	@Override
	public boolean checkout(int itemid) {
		try {
			dao.executeUpdate("update Room r set r.state = '打扫中' where r.roomid = (select i.room.roomid from SalesLineItem i where i.itemid = "+itemid+")");
			return dao.executeUpdate("update SalesLineItem i set i.checkout_time = NOW(),i.state = '已退房' where i.itemid = "+itemid);
		}catch(Exception ex) {
			ex.printStackTrace();
		}
		return false;
		
	}

	@Override
	public int getCheckinCustomerCount() {
		return Integer.parseInt(dao.uniqueResult("select count(*) from SalesLineItem i where i.state='已入住'"));
	}

	@Override
	public List<T> findBySalesid(int salesid) {
		return dao.list("from SalesLineItem i where i.sales.salesid = "+salesid);
	}

	@Override
	public boolean updateCustomerCount(int itemid, int count) {
		return dao.executeUpdate("update SalesLineItem i set i.count=i.count+"+count+" where i.itemid ="+itemid);
	}

}
